package com.controller.Hua;

import com.pojo.Hua.*;
import com.service.Hua.IMaterialWarehouseInService;
import com.service.Hua.IMaterialWarehouseService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("huaInWarehouse/")
public class MaterialWarehouseInController {
    @Autowired
    IMaterialWarehouseInService iMaterialWarehouseInService;
    //获取库存
    @GetMapping("getInMaterialWarehouse")
    public List<HuaMaterialInWarehouse> getMaterialWarehouse() {
        List<HuaMaterialInWarehouse> inWarehouse = iMaterialWarehouseInService.getInWarehouse();
        return inWarehouse;
    }

    //获得原材料下拉框
    @GetMapping("getMaterials")
    public List<HuaMaterial> getMaterials() {
        List<HuaMaterial> materials = iMaterialWarehouseInService.getMaterials();
        return materials;
    }

    @GetMapping("getMaterialPly")
    public List<HuaMaterialPly> getMaterialPly() {
        List<HuaMaterialPly> materialPly = iMaterialWarehouseInService.getMaterialPly();
        return materialPly;
    }

    //获得记录人员下拉框
    @GetMapping("getStaff")
    public List<Staff> getStaff() {
        List<Staff> staff = iMaterialWarehouseInService.getStaff();
        return staff;
    }

    @Autowired
    IMaterialWarehouseService iMaterialWarehouseService;
    //添加入库数据
    @PostMapping("addInMaterialWarehouse")
    public Res addInMaterialWarehouse(@RequestBody HuaMaterialInWarehouse huaMaterialInWarehouse) {
        Res res = new Res();
        Integer maxCode = iMaterialWarehouseInService.getMaxCode();
        Integer code = maxCode+1;
        huaMaterialInWarehouse.setMaterialInWarehouseCode(code.toString());
        Res res1 = iMaterialWarehouseInService.addInMaterialWarehouse(huaMaterialInWarehouse);
        Res res2 = iMaterialWarehouseService.addMaterialWarehouse(huaMaterialInWarehouse);
        Res res3 = iMaterialWarehouseService.upDateWarehouseTime(code.toString());
        if (res1.getCode() == 200 && res2.getCode() == 200){
            res.setCode(200);
            res.setMsg("入库成功");
        }else{
            res.setCode(404);
            res.setMsg("入库失败");
        }
        return res;
    }
}
